﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <title>添加品牌</title>
    <link rel="stylesheet" href="~/static/common/layui/css/layui.css" />
    <link rel="stylesheet" href="~/static/admin/css/style.css" />
    <script src="~/static/common/layui/layui.js"></script>
    <script src="~/static/common/jquery-3.3.1.min.js"></script>
    <script src="~/static/common/vue.min.js"></script>
</head>
<body>

    <!--右侧-->
    <div class="right">
        <!-- 配置文件 -->
        <script type="text/javascript" src="~/static/common/ueditor/ueditor.config.js"></script>
        <!-- 编辑器源码文件 -->
        <script type="text/javascript" src="~/static/common/ueditor/ueditor.all.js"></script>
        <fieldset class="layui-elem-field layui-field-title">
            <legend>添加品牌</legend>
        </fieldset>
        <div class="layui-form ">
            <div class="layui-form-item">
                <label class="layui-form-label">品牌名字</label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="title" placeholder="" autocomplete="off" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <img class="layui-upload-img" id="demo1" width="200" height="200" />
                    <p id="demoText"></p>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" class="layui-btn" id="test1">上传图片</button>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">描述</label>
                <div class="layui-input-inline">
                    <textarea type="text" cols="67" rows="5" name="key" id="desc"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否上架</label>
                <div class="layui-input-block">
                    <input type="checkbox" value="1" id="status" name="top" lay-text="是|否" lay-skin="switch" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">排序</label>
                <div class="layui-input-inline">
                    <input type="text" id="orderBy" name="title" placeholder="" autocomplete="off" class="layui-input" />
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" id="btn">立即提交</button>
                </div>
            </div>
        </div>
    </div>
    <script src="~/static/admin/js/config.js"></script>
    <script src="~/static/admin/js/script.js"></script>
</body>
</html>
<script type="text/javascript">
   var tupian=null;
     layui.use('upload', function () {
        var $ = layui.jquery
            , upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            , url: '/FileUpload/UploadImage'
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                $('#demo1').attr('src', res.FilePath);
                tupian = res.FilePath;
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
            }
        });
     });
    $("#btn").click(function () {
        var datas = {};
        datas.Name = $("#name").val();
        datas.Desc = $("#desc").val();
        datas.Logo = tupian;
        if ($("#status").get(0).checked) {
            datas.Status = 1;
        } else {
            datas.Status = 0;
        }
        datas.OrderBy = $("#orderBy").val();
       

        $.ajax({
            url: "/Brand/AddUpdateBrand",
            data: datas,
            type: "Post",
            success: function (data) {
                if (data.Success) {
                    //layer.msg("添加成功", { icon: 1, time: 2500, title: "提示框" });
                    layer.msg("添加成功");
                    window.location.href = '/Home/Brand_Manage';
                }
                else {
                    layer.msg("添加失败", { icon: 1, time: 2500, title: "提示" });
                }
            }
        });
    });
</script>